<?php


namespace app\home\model;


class NewsIssued extends Base
{
    /**
     * 获取数据集
     * @param int $class 类别，1置顶消息，2普通消息
     * @param int $type 类型，1行政，2党建，3工会
     * @param int $limit 数据条数，推荐3条，普通每次8条
     * @param int $length 数据长度，加载更多使用
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getDataList($class,$type,$limit = 8,$length = 0) {
        if($class == 1) {
            $map = [
                'status' => 1,
                'recommend' => 1
            ];
            $order = 'id desc';
        }else {
            $map = [
                'status' => 1,
            ];
            $order = 'id desc';
        }
        $front_cover = [1 => "158", 2 => "159", 3 => "160"];
        $map['type'] = $type;
        $res = $this->where($map)->limit($length,$limit)->order($order)->select();
        foreach ($res as $value) {
            if($class == 1) {
                if(empty($value['front_cover'])) {
                    $img = $front_cover[$value['type']];
                }else {
                    $img = $value['front_cover'];
                }
            }else {
                $img = $value['front_cover'];
            }
            $path = $this->get_cover($img);
            $value['path'] = $path ? thumb($path) : "";

        }
        return $res;
    }
}